<?php

namespace yiike\company\model;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\company\model\TtycCompany;

/**
* TtycSearch represents the model behind the search form about `yiike\company\model\TtycCompany`.
*/
class TtycSearch extends TtycCompany
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'weid', 'uid', 'max_sub', 'status', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['username', 'openid', 'name', 'idcard', 'tel', 'company', 'location_p', 'location_c', 'location_a', 'address', 'idcard_img', 'company_img', 'bank', 'payee', 'bank_account'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TtycCompany::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'weid' => $this->weid,
            'uid' => $this->uid,
            'max_sub' => $this->max_sub,
            'status' => $this->status,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'username', $this->username])
            ->andFilterWhere(['like', 'openid', $this->openid])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'idcard', $this->idcard])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'company', $this->company])
            ->andFilterWhere(['like', 'location_p', $this->location_p])
            ->andFilterWhere(['like', 'location_c', $this->location_c])
            ->andFilterWhere(['like', 'location_a', $this->location_a])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'idcard_img', $this->idcard_img])
            ->andFilterWhere(['like', 'company_img', $this->company_img])
            ->andFilterWhere(['like', 'bank', $this->bank])
            ->andFilterWhere(['like', 'payee', $this->payee])
            ->andFilterWhere(['like', 'bank_account', $this->bank_account]);

return $dataProvider;
}
}